package com.itheima.controller;

import com.github.pagehelper.Page;
import com.itheima.entity.PageResult;
import com.itheima.entity.Result;
import com.itheima.pojo.ExceptionLog;
import com.itheima.pojo.SysLog;
import com.itheima.service.ExceptionLogService;
import com.itheima.service.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping("/log")
@RestController
@CrossOrigin
public class LogController {

    @Autowired
    private ExceptionLogService exceptionLogService;

    @Autowired
    private SysLogService sysLogService;

    @PostMapping("/getExceptionList")
    public Result getExceptionList(@RequestBody Map<String,Object> exceptionLogVO){
        //封装结果集
        Page<ExceptionLog> page = exceptionLogService.getExceptionList(exceptionLogVO);
        PageResult<ExceptionLog> pageResult = new PageResult<>();
        pageResult.setRecords(page.getResult());
        pageResult.setCurrent((long) page.getPageNum()+1);
        pageResult.setOptimizeCountSql(true);
        pageResult.setSize((long) page.getPageSize());
        pageResult.setTotal(page.getTotal());
        pageResult.setSearchCount(true);
        return new Result("success",pageResult);
    }

    @PostMapping("/getLogList")
    public Result getLogList(@RequestBody Map<String,Object> sysLogVO){
        Page<SysLog> pageList = sysLogService.getLogList(sysLogVO);
        PageResult<SysLog> pageResult = new PageResult<>();
        pageResult.setRecords(pageList.getResult());
        pageResult.setCurrent((long) pageList.getPageNum()+1);
        pageResult.setOptimizeCountSql(true);
        pageResult.setSize((long) pageList.getPageSize());
        pageResult.setTotal(pageList.getTotal());
        pageResult.setSearchCount(true);
        return new Result("success",pageResult);
    }
}
